<!-- @Author: Yu_Bo -->
<template>
	<view class="money">
		<view class="money_info">
			<image class="info_bg" src="@/static/images/img/money_background.png" mode=""></image>
			<view class="info_main">
				<view class="main_title">
					<view class="title">
						我的余额
					</view>
					<view class="title_right">
						<view class="right" @click="$navTo('/pagesWo/capital/index')">
							<image src="@/static/images/img/money_icon.png" mode=""></image>
							资金明细
						</view>
						<view class="right" @click="$navTo('/pagesWo/bright/index')">
							<image src="@/static/images/img/money_icon.png" mode=""></image>
							提现明细
						</view>
					</view>
				</view>
				<view class="main_num">
					<view class="left">
						{{money}}
					</view>
					<view class="right">
						<view class="right_txt">
							<view class="txt">
								￥{{withdrawn}}
							</view>
							<view class="tip">
								已提现
							</view>
						</view>
						<view class="right_txt">
							<view class="txt">
								￥{{commission}}
							</view>
							<view class="tip">
								累计收入
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!--  -->
		<view class="money_title">
			提现金额
		</view>
		<!--  -->
		<view class="money_list">
			<view class="list" :class="listIndex==index?'active':''" v-for="(item,index) in list" :key="index" @click="moneyBtn(index)">
				{{item.value}}
			</view>
		</view>
		<!--  -->
		<view class="money_input">
			<view class="input_icon">
				￥
			</view>
			<view class="input_txt">
				<u-input v-model="moneyInput" type="digit" :clearable="false" placeholder="自定义提现金额" />
			</view>
		</view>
		<!--  -->
		<view class="money_tip">
			提现手续费{{service_charge}}%，最低提现{{low_withdrawal_money}}元，最高提现{{hight_withdrawal_money}}元
		</view>
		<!--  -->
		<view class="money_upload">
			<view class="up_txt">
				请添加收款二维码
			</view>
			<view class="up_btn" @click="upimageBtn">
				<image v-if="fullurl" :src="fullurl" mode="aspectFit"></image>
				<image v-else src="@/static/images/img/upload_icon.png" mode=""></image>
			</view>
		</view>
		<!--  -->
		<view class="money_btn">
			<view class="btn" @click="submitBtn">
				<u-loading v-if="loading" mode="flower" color="#ffffff"></u-loading>
				<image v-else src="@/static/images/img/weixin.png" mode=""></image>
				提现到微信
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return{
				// 
				money: "0.00",
				withdrawn: "0.00",
				commission: "0.00",
				// 
				service_charge: "0.00",
				low_withdrawal_money: "0.00",
				hight_withdrawal_money: "0.00",
				// 
				listIndex: 0,
				list: [
					{id: 10, value: '10元'},
					{id: 20, value: '20元'},
					{id: 50, value: '50元'},
					{id: 100, value: '100元'},
					{id: 300, value: '300元'},
					{id: 500, value: '500元'},
				],
				moneyInput: "",
				// 
				fullurl: "",
				url: "",
				loading: false,
			}
		},
		computed: {},
		onLoad() {},
		onShow() {
			this.getInfo()
			this.getDeatils()
		},
		methods: {
			getInfo() {
				var that = this
				that.$httpApi.myWallet().then((res) => {
					if (res.code == 1) {
						that.money = res.data.user.money
						that.withdrawn = res.data.user.withdrawn
						that.commission = res.data.user.commission
					}
				})
			},
			getDeatils() {
				var that = this
				that.$httpApi.withdraw().then((res) => {
					if (res.code == 1) {
						that.service_charge = res.data.service_charge
						that.low_withdrawal_money = res.data.low_withdrawal_money
						that.hight_withdrawal_money = res.data.hight_withdrawal_money
					}
				})
			},
			// 选中金额
			moneyBtn(index) {
				this.listIndex = index
			},
			// 提现
			submitBtn() {
				var that = this
				if (that.url == '') {
					that.$tips.showToast('请添加收款二维码')
					return
				}
				if(that.loading) return
				that.loading = true
				var params = {
					money: that.moneyInput*100 ? that.moneyInput : that.list[that.listIndex].id,
					code_image: that.url
				}
				that.$httpApi.myCash(params).then((res) => {
					that.loading = false
					if (res.code == 1) {
						that.$tips.showToast(res.msg)
						that.getInfo()
					}
				})
			},
			// 上传图片
			upimageBtn() {
				var that = this
				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function(res) {
						const tempFilePaths = res.tempFilePaths;
						that.updateImage(tempFilePaths[0])
					},
					error: function(e) {
						// console.log(e);
					}
				})
			},
			// 上传
			updateImage(src) {
				var that = this
				that.$tips.showLoading('上传中')
				const uploadTask = uni.uploadFile({
					url: that.$baseVal.baseUrl+'/api/common/upload',
					filePath: src,
					name: 'file',
					formData: {},
					header: {
						'token': uni.getStorageSync('token')
					},
					success: function(uploadFileRes) {
						that.$tips.hideLoading()
						var res = JSON.parse(uploadFileRes.data)
						console.log(res)
						if(res.code==1){
							that.fullurl = res.data.fullurl
							that.url = res.data.url
						}else{
							that.$tips.showToast(res.msg)
						}
					}
				});
			},
		},
	}
</script>

<style lang='scss' scoped>
	.money {
		width: 100%;
		padding: 30rpx;
		
		.money_info {
			position: relative;
			width: 100%;
			height: 240rpx;
			
			.info_bg {
				position: absolute;
				top: 0;
				left: 0;
				z-index: 1;
				display: block;
				width: 100%;
				height: 100%;
			}
			
			.info_main {
				position: absolute;
				top: 0;
				left: 0;
				z-index: 2;
				width: 100%;
				height: 100%;
				padding: 0 30rpx;
				
				.main_title {
					width: 100%;padding-top: 30rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					
					.title {
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 28rpx;
						color: #FFFFFF;
					}
					
					.title_right {
						display: flex;
						align-items: center;
						justify-content: space-between;
						
						.right {
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							font-size: 24rpx;
							color: #FFFFFF;
							margin-left: 50rpx;
							display: flex;
							align-items: center;
							
							image {
								display: block;
								width: 26rpx;
								height: 26rpx;
								margin-right: 10rpx;
							}
						}
					}
				}
				
				.main_num {
					width: 100%;
					padding-top: 50rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					
					.left {
						font-family: PingFang SC, PingFang SC;
						font-weight: 800;
						font-size: 60rpx;
						color: #FFFFFF;
					}
					
					.right {
						display: flex;
						align-items: center;
						
						.right_txt {
							margin-left: 50rpx;
							color: #ffffff;
							text-align: center;
							
							.txt {
								font-family: PingFang SC, PingFang SC;
								font-weight: 400;
								font-size: 32rpx;
							}
							
							.tip {
								font-family: PingFang SC, PingFang SC;
								font-weight: 400;
								font-size: 24rpx;
							}
						}
					}
				}
			}
		}
		
		.money_title {
			width: 100%;
			padding-top: 40rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 28rpx;
			color: #222222;
		}
		
		.money_list {
			width: 100%;
			padding-top: 6rpx;
			display: flex;
			flex-wrap: wrap;
			
			.list {
				width: 214rpx;
				height: 100rpx;
				line-height: 100rpx;
				text-align: center;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #222222;
				margin-top: 24rpx;
				margin-right: 24rpx;
				border: 2rpx solid #F7F7F7;
				background: #F7F7F7;
				border-radius: 12rpx 12rpx 12rpx 12rpx;
			}
			
			.list:nth-child(3n) {
				margin-right: 0;
			}
			
			.active {
				color: #5A68FF;
				border: 2rpx solid #5A68FF;
				background: #E9EBFF;
			}
		}
		
		.money_input {
			width: 100%;
			padding-top: 30rpx;
			border-bottom: 2rpx solid rgba(34, 34, 34, 0.05);
			display: flex;
			align-items: center;
			
			.input_icon {
				width: 50rpx;
				height: 100rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 40rpx;
				color: #222222;
				display: flex;
				align-items: center;
			}
			
			.input_txt {
				width: calc(100% - 50rpx);
				height: 100rpx;
				display: flex;
				align-items: center;
				
				u-input {
					width: 100%;
				}
				::v-deep .u-input{
					width: 100%;
					
					.u-input__input {
						width: 100%;
						color: #333333;
						font-size: 32rpx !important;
					}
				}
			}
		}
		
		.money_tip {
			width: 100%;
			padding: 30rpx 0;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 24rpx;
			color: #999999;
		}
		
		.money_upload {
			width: 100%;
			margin-top: 10rpx;
			padding: 30rpx;
			background: #F6F6F6;
			border-radius: 20rpx;
			
			.up_txt {
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #222222;
			}
			
			.up_btn {
				width: 182rpx;
				height: 182rpx;
				margin-top: 30rpx;
				
				image {
					display: block;
					width: 100%;
					height: 100%;
					border-radius: 20rpx;
				}
			}
		}
		
		.money_btn {
			width: 100%;
			padding: 80rpx 0 60rpx;
			display: flex;
			justify-content: center;
			
			.btn {
				width: 360rpx;
				height: 80rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #FFFFFF;
				background: #21DE73;
				border-radius: 40rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				
				image {
					display: block;
					width: 36rpx;
					height: 30rpx;
					margin-right: 10rpx;
				}
			}
		}
	}
</style>